package com.example.demo.image;


import com.example.demo.json.Person;
import com.example.demo.json.PersonService;
import dev.langchain4j.data.message.ImageContent;
import dev.langchain4j.data.message.TextContent;
import dev.langchain4j.data.message.UserMessage;
import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.service.AiServices;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Base64;
import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/image/api")
public class ImageAPI {

    final ChatLanguageModel audioModel;

    @GetMapping("/low/chat")
    public String highChat(@RequestParam(value = "message")String message) throws IOException {
        File file=new File("D:\\pools\\demo\\document\\basketball.jpg");
        byte[] bytes = Files.readAllBytes(file.toPath());
        UserMessage userMessage = UserMessage.from(TextContent.from(message),
                ImageContent.from(Base64.getEncoder().encodeToString(bytes), "image/jpg"));
        return audioModel.chat(List.of(userMessage)).aiMessage().text();

    }
}
